const theme = (uni.getStorageSync('theme') || 'light')

const state = () => ({
	theme: theme,    
})

const getters = {
	getTheme(state) {
		return state.theme
	}, 
}

const mutations = {
	updataTheme(state, data) {
		state.theme = data
		try {
			uni.setStorageSync('theme', data);
		} catch (e) {}
	}, 
}

const actions = {
	setTheme({dispatch, commit, state }, data){
		/* #ifdef H5 */
		window.document.documentElement.setAttribute('data-theme', data);
		/* #endif */
		commit('updataTheme', data)
	},
}

export default {
	namespaced: true,
	getters,
	state,
	mutations,
	actions
}